Skip to content

RFC: Deprecate type juggling to and from bool for function type juggling context #18879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jun 19, 2025

RFC: https://wiki.php.net/rfc/deprecate-function-bool-type-juggling

@nicolas-grekas this should allow you to check if SF is affected :)

@nicolas-grekas
Copy link
Contributor

nicolas-grekas commented Jun 23, 2025

Thanks for the PR. I tried it on Symfony and I get tons of deprecations, of course.
It would be great to fix them one by one to get a better understanding of the impact this PR could have on userland.

I'm already wondering if we shouldn't discuss about both directions of the conversion separately. It looks more of a smell to accept a bool where eg a string is expected, than to accept a string where a bool it required.

This maps to structs like if ($boo) {...}. If this is accepted for any types (as it should), then the conversion rules are plain explicit and well known for the to-bool direction.

Places I found where the direction is from-bool are way less legit at first glance.

Can you try running the test suite? Here is the doc about how to: https://symfony.com/doc/current/contributing/code/tests.html

Then look at random deprecations and try to fix some to get some taste of the deprecation :)

@Girgias
Copy link
Member Author

Girgias commented Jun 23, 2025

Thanks for the PR. I tried it on Symfony and I get tons of deprecations, of course. It would be great to fix them one by one to get a better understanding of the impact this PR could have on userland.

I'm already wondering if we shouldn't discuss about both directions of the conversion separately. It looks more of a smell to accept a bool where eg a string is expected, than to accept a string where a bool it required.

While I agree that coercing from bool to something else seem to always indicate a bug from doing fixes to the php-src tests, I have found a bunch of bugs in our test suite where strings are coerced to bool.
In our test suite the biggest causes for deprecation churn is using 0 and 1 for false and true respectively, and old and useless ZPP tests.

And the engine/type system simplification of true|false being the same as bool can't happen if coercing to bool is not deprecated :-/

This maps to structs like if ($boo) {...}. If this is accepted for any types (as it should), then the conversion rules are plain explicit and well known for the to-bool direction.

This is not exactly true, as values of type null, object, array, or resource do not pass a bool type check but are accepted by if ($value) {}

Places I found where the direction is from-bool are way less legit at first glance.

Can you try running the test suite? Here is the doc about how to: https://symfony.com/doc/current/contributing/code/tests.html

Then look at random deprecations and try to fix some to get some taste of the deprecation :)

I'll have a look at them soon-ish and will ask for help if I can't run the test suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants